#include "coursesection.h"
#include "course.h"
#include "logger.h"

using namespace std;

CourseSection::CourseSection() // default constructor
{
	// TODO:  implement
}

CourseSection::CourseSection( const string& id,  
							  const string& prof,
							  const string& location,
							  int semester_number,
							  SectionType type,
							  boost::weak_ptr<Course> course,
							  boost::weak_ptr<CourseSection> parent ):
	professor(prof),
	room(location),
	ID(id),
	semester(semester_number),
	sectionOf(course),
	parentSection(parent),
	sectionType(type)
{

}


CourseSection::~CourseSection() // destructor
{

}

string CourseSection::getProfessor()
{
	return professor;
}

boost::weak_ptr<Course> CourseSection::getCourse()
{
	return sectionOf;
}

int CourseSection::getSemester()
{
	return semester;
}

vector<int> CourseSection::getTime(int t) const
{
	switch(t){
		case 1: return time1;
		case 2: return time2;
		default: 
			vector<int> error;
			error.push_back(-1);
			return error;
	}
}

CourseSection::SectionType CourseSection::getType() const
{
	return sectionType;
}

string CourseSection::getID() const
{
	return ID;
}

std::vector< boost::shared_ptr<CourseSection> > CourseSection::getSubsections() const
{
	return subSections;
}

boost::weak_ptr<CourseSection> CourseSection::getParent()
{
	return parentSection;
}
const CourseSection::timing CourseSection::times() const
{
	return _time;
}
///Add a time to the vector
void CourseSection::time(boost::posix_time::time_period begin_end)
{
	if( begin_end.is_null() )
		{
			Logger::instance()->error("Time error." ,0);
			// Do something throw?
		}

	//Is anything missing?
	// Should i put anything else here?
	_time.push_back(begin_end);
}
void CourseSection::time(boost::posix_time::ptime begin, boost::posix_time::ptime end)
{
	//Anything more elegant here?
	time(time_period(begin,end));
}
int CourseSection::number_subsections()
{
	int count = 0;
	for(int i = 0 ; subSections.size(); i++)
		{
			count += 1+ subSections[i]->number_subsections();
		} 
	return count;
}
